﻿using System;
using System.Collections.Generic;
using System.ServiceModel;
using System.ServiceModel.Activation;
using System.ServiceModel.Web;
using IapApp;
using IapService.Data;
using IapService.Entity;

namespace IapService.Service
{
    [ServiceContract]
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]
    public class ClientService : Service
    {
        [WebGet(UriTemplate = "{id}")]
        public ServiceResponse<Client> Get(string id)
        {
            return Execute(() => new ClientData().Get(Convert.ToInt32(id)));
        }

        [WebGet(UriTemplate = "")]
        public ServiceResponse<List<Client>> GetList()
        {
            return Execute(() => new ClientData().Get());
        }

        [WebInvoke(UriTemplate = "/" + JOB_SAVE, Method = "POST", RequestFormat = WebMessageFormat.Json)]
        public ServiceResponse<Client> Save()
        {
            return Execute(() => new ClientData().Save(TranslateFromPost<Client>()));
        }

        [WebInvoke(UriTemplate = "/" + JOB_REMOVE, Method = "POST", RequestFormat = WebMessageFormat.Json)]
        public ServiceResponse<Client> Remove()
        {
            return Execute(() => new ClientData().Remove(TranslateFromPost<Client>()));
        }
    }
}